#ifndef T1_SPI_H_
#define T1_SPI_H_

#include "iodef.h"

typedef struct {
        __IO uint32_t TXREG;
        __IO uint32_t RXREG;
        __IO uint32_t CSTAT;
        __IO uint32_t INTSTAT;
        __IO uint32_t INTEN;
        __IO uint32_t INTCLR;
        __IO uint32_t GCTL;
        __IO uint32_t CCTL;
        __IO uint32_t SPBRG;
        __IO uint32_t RXDNR;
        __IO uint32_t SCSR;
}spi_reg_t;

/* CSTAT */
#define SPI_CSTAT_TX_FULL       _BIT(2)
#define SPI_CSTAT_RX_AVL        _BIT(1)
#define SPI_CSTAT_TX_EPT        _BIT(0)

/* INTSTAT, INTEN, INTCLR */
#define SPI_INT_TX_EPT          _BIT(6)
#define SPI_INT_RX_FULL         _BIT(5)
#define SPI_INT_RX_MATCH        _BIT(4)
#define SPI_INT_RX_OERR         _BIT(3)
#define SPI_INT_UNDERRUN        _BIT(2)
#define SPI_INT_RX_AVL          _BIT(1)
#define SPI_INT_TX_AVL          _BIT(0)

/* GCTL */
#define SPI_TX_TRIG_N_MSK       _MASK(7, 2)
#define SPI_TX_TRIG_N(n)        _VALUE(7, (n))
#define SPI_RX_TRIG_N_MSK       _MASK(5, 2)
#define SPI_RX_TRIG_N(n)        _VALUE(5, (n))
#define SPI_RX_EN               _BIT(4)
#define SPI_TX_EN               _BIT(3)
#define SPI_SEL_MASTER          _BIT(2)
#define SPI_INT_EN              _BIT(1)
#define SPI_EN                  _BIT(0)

/* CCTL */
#define SPI_CHAR_8BIT           _BIT(3)
#define SPI_LSB_FIRST           _BIT(2)
#define SPI_CKPL                _BIT(1)
#define SPI_CKPH                _BIT(0)

#define SPI0    ((spi_reg_t *)T1_SPI0_BASE)
#define SPI1    ((spi_reg_t *)T1_SPI1_BASE)

#endif /* T1_SPI_H_ */
